﻿using System;
using System.IO;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Navigation;
using System.Xml.Linq;
using System.Linq;
using Hi_Baidu.Cache;
using Hi_Baidu.ProcessModel;
using Hi_Baidu.Remote;
using Hi_Baidu.FileShare;
using Hi_Baidu.FileShare.User;

namespace Hi_Baidu
{
	public partial class Win_Main
	{
		public Win_Main()
		{
            this.InitializeComponent();
            LoginProcessModel.LOGINSTATE = LoginProcessModel.LOGIN.LOGINED;
            LoginProcessModel.TOOLTIP_NOTIFY_ICON();
            if (DeclareCacheManager.itemControlCacheManager == null)
            {
                DeclareCacheManager.itemControlCacheManager = new ItemControlCacheManager(new System.Timers.Timer(), 5000);
            }
            if(DeclareCacheManager.friendControlCacheManager == null)
            {
                DeclareCacheManager.friendControlCacheManager = new FriendControlCacheManager(new System.Timers.Timer(), 5000);
            }
		}

        private void Window_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            try
            {
                if (e.ChangedButton == MouseButton.Left)
                {
                    this.DragMove();
                    Init();
                }
            }
            catch { }
        }

        /// <summary>
        ///     主界面初始化动作
        /// </summary>
        private void Init()
        {
            //创建好友树右键菜单
            this.TV_FriendList.ContextMenu = GetContextMenuViewModel.GetFriendTreeViewContextMenu("../XML_Resource/ContextMenu_FriendTreeView.xml");
        }

        private void Border_MouseDown(object sender, MouseButtonEventArgs e)
        {
            
        }

        private void Border_MouseDown_1(object sender, MouseButtonEventArgs e)
        {
            this.ShowPostAddFriend();
        }

        /// <summary>
        ///     显示添加好友窗口
        /// </summary>
        public void ShowPostAddFriend()
        {
            //如果当前不存在添加用户窗口 
            if (!Globle.popWindowManager.Equals("PostAddFriend"))
            {
                Win_PostAddFriend win_PostAddFriend = new Win_PostAddFriend("PostAddFriend");
                win_PostAddFriend.Show();
                Globle.popWindowManager.Add(win_PostAddFriend);
            }
            else
            {
                (Globle.popWindowManager.GetMemberByKey("PostAddFriend") as Win_PostAddFriend).Activate();
            }
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            ////注册通道
            //Remote.RemoteConnect.RegisterChannel("Hi_Baidu.exe.config");
            ////得到远程对象 
            //FileShareProcessor fileShareProcessor = new FileShareProcessor();
            //fileShareProcessor.CreateFileShareByUser(new FileShareUser("yangjie"));
            //PublicCommon publicCommon = new PublicCommon();
            //fileShareProcessor.CreateUserEventArgs += new CreateFileShareUser(publicCommon.CreateFileShareUser);
        }

        private void txt_NotifyNickName_TextChanged(object sender, TextChangedEventArgs e)
        {

        }
	}
}